// com/interview/case03/Main.java
package com.interview.case03;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class Main {
    public static void main(String[] args) {
        // 创建购物车
        ShoppingCart cartC = new ShoppingCart();

        // 顾客C购买的水果斤数
        int applesC = 3;        // 3斤苹果
        int strawberriesC = 5;  // 5斤草莓
        int mangoesC = 2;       // 2斤芒果

        // 将水果添加到购物车
        Fruit apple = new Apple();
        Fruit strawberry = new Strawberry();
        Fruit mango = new Mango();
        cartC.addFruit(apple, applesC);
        cartC.addFruit(strawberry, strawberriesC);
        cartC.addFruit(mango, mangoesC);

        // 计算总价
        BigDecimal totalC = cartC.calculateTotalPrice();

        // 预期总价：
        // 苹果: 3 * 8.00 = 24.00
        // 草莓: 5 * 13.00 * 0.80 = 52.00
        // 芒果: 2 * 20.00 = 40.00
        // 总计: 24.00 + 52.00 + 40.00 = 116.00 元
        BigDecimal expectedC = new BigDecimal("3").multiply(new BigDecimal("8.00"))
                                .add(new BigDecimal("5").multiply(new BigDecimal("13.00")).multiply(new BigDecimal("0.80")))
                                .add(new BigDecimal("2").multiply(new BigDecimal("20.00")));

        // 设置小数点精度
        totalC = totalC.setScale(2, RoundingMode.HALF_UP);
        expectedC = expectedC.setScale(2, RoundingMode.HALF_UP);

        // 输出结果
        System.out.println("顾客C购买的总价: " + totalC + " 元");

        // 验证计算结果
        if (totalC.compareTo(expectedC) == 0) {
            System.out.println("测试通过！");
        } else {
            System.out.println("测试失败！预期: " + expectedC + " 元, 实际: " + totalC + " 元");
        }
    }
}
